package com.xxxcompany.shop.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xxxcompany.shop.service.IUserService;
import com.xxxcompany.shop.service.impl.UserServiceImpl;

@WebServlet("/Registerchk")
public class RegisterCheckServlet extends HttpServlet {
	IUserService userService = new UserServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();

		String username = req.getParameter("username");
		String password = req.getParameter("password");
		String repassword = req.getParameter("repassword");

		if (repassword.equals(password)) {

			if (userService.register(username, repassword)) {
				pw.write("注册成功");
			} else {
				pw.write("注册失败");
			}
		} else {
			pw.write("重复密码与密码不一致，请重新输入！");
		}

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}